class Solution
{
public:
    int halveArray(vector<int> &nums)
    {
        double sum = 0;
        for (auto e : nums)
            sum += e;
        double target = static_cast<double>(sum) / 2;
        priority_queue<double> q(nums.begin(), nums.end());
        double now = 0;
        int time = 0;
        while (now < target)
        {
            double e = q.top();
            q.pop();
            q.push(e /= 2);
            now += e;
            ++time;
        }
        return time;
    }
};